package com.fernfx.xingtan.my.ui;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.fernfx.xingtan.R;
import com.fernfx.xingtan.common.base.BaseActivity;
import com.fernfx.xingtan.my.adapter.MyBackCardsListAdapter;
import com.fernfx.xingtan.my.contract.MyBackCardsListContract;
import com.fernfx.xingtan.my.entity.MyBackCardsListEntity;
import com.fernfx.xingtan.my.presenter.MyBackCardsListPresenter;
import com.fernfx.xingtan.utils.CollectionUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/8/20.
 */

public class MyBackCardsListActivity extends BaseActivity implements MyBackCardsListContract.View,View.OnClickListener{
    public static void start(Context context) {
        Intent intent = new Intent(context,MyBackCardsListActivity.class);
        context.startActivity(intent);
    }

    @BindView(R.id.black_cards_list_liv)
    ListView blackCardsListLiv;
    @BindView(R.id.no_find_binding_back_card_tv)
    TextView noFindBindingBackCardTv;
    @BindView(R.id.tv_refund_project_title)
    TextView refundProjectTitleTv;

    private MyBackCardsListAdapter myBackCardsListAdapter;
    //adapter list
    List<MyBackCardsListEntity.ObjBean> cardsList = null;

    private MyBackCardsListContract.Presenter presenter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_my_black_cards_list;
    }

    @Override
    protected void initView() {
        setToolbarTitle("银行卡");
        //设置添加银行卡
        refundProjectTitleTv.setVisibility(View.VISIBLE);
        refundProjectTitleTv.setText("添加银行卡");
    }

    @Override
    protected void initData() {
        presenter = new MyBackCardsListPresenter();
        presenter.init(this);
        requestArgsMap.clear();
        presenter.request(requestArgsMap);
        //init adapter
        cardsList = new ArrayList<>(0);
        myBackCardsListAdapter = new MyBackCardsListAdapter(mContext,cardsList);
        blackCardsListLiv.setAdapter(myBackCardsListAdapter);
    }

    @Override
    public BaseActivity getActivity() {
        return this;
    }

    @Override
    public void showBackCardsList(List<MyBackCardsListEntity.ObjBean> cardsList) {
        if (CollectionUtil.isEmpty(cardsList)) {
            noFindBindingBackCardTv.setVisibility(View.VISIBLE);
            blackCardsListLiv.setVisibility(View.GONE);
            return;
        }
        noFindBindingBackCardTv.setVisibility(View.GONE);
        blackCardsListLiv.setVisibility(View.VISIBLE);
        //刷新adapter
        this.cardsList.clear();
        this.cardsList.addAll(cardsList);
        myBackCardsListAdapter.notifyDataSetChanged();
    }

    @OnClick({R.id.tv_refund_project_title})
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_refund_project_title:
                MyBankCardsActivity.start(mContext);
                break;
        }
    }
}
